package raphaelMatcher;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

//import wikiextract.data.util.Util;

public class DelimitedWriter {

	private BufferedWriter bw;
	
	public DelimitedWriter(String filename)
	throws IOException
	{
		bw = new BufferedWriter(new OutputStreamWriter
				(new FileOutputStream(filename), "utf-8"));		
	}

	public DelimitedWriter(String filename, boolean append)
	throws IOException
	{
		bw = new BufferedWriter(new OutputStreamWriter
				(new FileOutputStream(filename, append), "utf-8"));		
	}

	public DelimitedWriter(String filename, String charset)
	throws IOException
	{
		bw = new BufferedWriter(new OutputStreamWriter
				(new FileOutputStream(filename), charset));		
	}
	
	public void write(String... cols) 
	throws IOException {
		if (cols.length == 0) return;
		
		bw.write(Util.escape(cols[0]));
		for (int i=1; i < cols.length; i++)
			bw.write("\t" + Util.escape(cols[i]));
		bw.write("\n");
	}
	
	public void close() 
	throws IOException {
		bw.close();		
	}
	
	public void flush()
	throws IOException {
		bw.flush();
	}
}
